<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="http://lcalhost:3000/users/login" method="post">
        <fieldset>
            <legend>登入</legend>
            用户名:
            <input type="text" id="username" name="username">
            <br>
            密码:
            <input type="password" id="password" name="password">
            <br>
            <input type="submit" id="btn" value="登入">
        </fieldset>
    </form>
</body>

</html>
<script>

    btn.onclick = function (e) {
        e.preventDefault();
        let usn = username.value;
        let pass = password.value;
        console.log(usn)
        console.log(pass);

        //发起请求

        fetch("http://localhost:3000/users/login", {
            method: 'post',
            body: JSON.stringify({
                username: usn,
                password: pass
            }),
            headers: {
                "content-type": "application/json"
            }
        })
            .then(body => body.json())
            .then(res => {
                console.log(res)
            })
    }
</script>